package com.heiye.quiz.biz.controller;

import com.heiye.framework.biz.operationlog.aspect.ApiOperationLog;
import com.heiye.framework.common.response.Response;
import com.heiye.quiz.api.dto.req.CheckNoteIsExistReqDTO;
import com.heiye.quiz.api.dto.req.FindQuizCreatorReqDTO;
import com.heiye.quiz.api.dto.resp.CheckQuizIsExistRespDTO;
import com.heiye.quiz.api.dto.resp.FindQuizCreatorRespDTO;
import com.heiye.quiz.biz.model.vo.req.*;
import com.heiye.quiz.biz.model.vo.rsep.FindQuizIsLikeRspVO;
import com.heiye.quiz.biz.model.vo.rsep.FindQuizzesRspVO;
import com.heiye.quiz.biz.service.QuizService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: heiye
 * @date: 2025/03/17 下午10:33
 * @version: v1.0.0
 * @description: 问题
 */
@Slf4j
@RestController
@RequestMapping("/quiz")
public class QuizController {

    @Resource
    private QuizService quizService;

    /**
     * 问题发布
     *
     * @param publishQuizReqVO
     * @return
     */
    @PostMapping("/publish")
    @ApiOperationLog(description = "问题发布")
    public Response<?> publishQuiz(@Validated @RequestBody PublishQuizReqVO publishQuizReqVO) {
        return quizService.publishQuiz(publishQuizReqVO);
    }

    /**
     * 问题详情
     *
     * @param findQuizDetailReqVO
     * @return
     */
    @PostMapping("/detail")
    @ApiOperationLog(description = "问题详情")
    public Response<?> findQuizDetail(@Validated @RequestBody FindQuizDetailReqVO findQuizDetailReqVO) {
        return quizService.findQuizDetail(findQuizDetailReqVO);
    }

    /**
     * 问题更新
     *
     * @param updateQuizReqVO
     * @return
     */
    @PostMapping("/update")
    @ApiOperationLog(description = "笔记修改")
    public Response<?> updateQuiz(@Validated @RequestBody UpdateQuizReqVO updateQuizReqVO) {
        return quizService.updateQuiz(updateQuizReqVO);
    }

    /**
     * 问题删除
     *
     * @param deleteQuizReqVO
     * @return
     */
    @PostMapping("/delete")
    @ApiOperationLog(description = "笔记删除")
    public Response<?> deleteQuiz(@Validated @RequestBody DeleteQuizReqVO deleteQuizReqVO) {
        return quizService.deleteQuiz(deleteQuizReqVO);
    }

    /**
     * 批量查询问题
     *
     * @param findQuizzesReqVO
     * @return
     */
    @PostMapping("/list")
    @ApiOperationLog(description = "批量查询问题")
    public Response<FindQuizzesRspVO> findQuizzes(@Validated @RequestBody FindQuizzesReqVO findQuizzesReqVO) {
        return quizService.findQuizzes(findQuizzesReqVO);
    }

    /**
     * 问题点赞
     *
     * @param likeQuizReqVO
     * @return
     */
    @PostMapping("/like")
    @ApiOperationLog(description = "问题点赞")
    public Response<?> likeQuiz(@Validated @RequestBody LikeQuizReqVO likeQuizReqVO) {
        return quizService.likeQuiz(likeQuizReqVO);
    }

    /**
     * 取消问题点赞
     *
     * @param unlikeQuizReqVO
     * @return
     */
    @PostMapping("/unlike")
    @ApiOperationLog(description = "问题取消点赞")
    public Response<?> unlikeQuiz(@Validated @RequestBody UnlikeQuizReqVO unlikeQuizReqVO) {
        return quizService.unlikeQuiz(unlikeQuizReqVO);
    }

    /**
     * 查询用户是否点赞了该问题
     *
     * @param findQuizIsLikeReqVO
     * @return
     */
    @PostMapping(value = "/isLikedData")
    @ApiOperationLog(description = "查询用户是否点赞了该问题")
    public Response<FindQuizIsLikeRspVO> isLikedData(@Validated @RequestBody FindQuizIsLikeReqVO findQuizIsLikeReqVO) {
        return quizService.isLikedData(findQuizIsLikeReqVO);
    }

    // ===================================== 对其他服务提供的接口 =====================================

    /**
     * 检查笔记是否存在
     *
     * @param checkNoteIsExistReqDTO
     * @return
     */
    @PostMapping("/checkNoteIsExist")
    @ApiOperationLog(description = "检查笔记是否存在")
    public Response<CheckQuizIsExistRespDTO> checkNoteIsExist(@Validated @RequestBody CheckNoteIsExistReqDTO checkNoteIsExistReqDTO) {
        return quizService.checkNoteIsExist(checkNoteIsExistReqDTO);
    }

    /**
     * 获取问题作者信息
     *
     * @param findQuizCreatorReqDTO
     * @return
     */
    @PostMapping("/findQuizCreator")
    @ApiOperationLog(description = "查询问题作者信息")
    public Response<FindQuizCreatorRespDTO> findQuizCreator(@Validated @RequestBody FindQuizCreatorReqDTO findQuizCreatorReqDTO) {
        return quizService.findQuizCreator(findQuizCreatorReqDTO);
    }
}
